import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {PageParam} from "../../api/api.service";
import {GOODS} from "../../api/goods-api";

/**
 * Generated class for the ExchangeRecordPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-exchange-record',
  templateUrl: 'exchange-record.html',
})
export class ExchangeRecordPage {
  pageParam:PageParam;
  hasMore:boolean = true;
  orderList = [];
  // exchanges = [
  //   {
  //     id:'1',
  //     image: 'http://placehold.it/75x75',
  //     title:'礼品名称',
  //     score:100,
  //     status:'兑换成功',
  //     date: new Date()
  //   },{
  //     id:'2',
  //     image: 'http://placehold.it/75x75',
  //     title:'礼品名称',
  //     score:100,
  //     status:'兑换成功',
  //     date: new Date()
  //   },{
  //     id:'3',
  //     image: 'http://placehold.it/75x75',
  //     title:'礼品名称',
  //     score:100,
  //     status:'兑换成功',
  //     date: new Date()
  //   },
  // ];

  constructor(public GOODS:GOODS, public navParams: NavParams) {
  }

  ionViewDidLoad() {
    document.title='兑换记录';
    console.log('ionViewDidLoad ExchangeRecordPage');
    this.doRefresh();
  }
  doRefresh(refresher?) {
    this.pageParam = new PageParam()
    this.GOODS.getScoreOrderList(v => {
      this.orderList = v.content
      this.hasMore = !v.last;
      if (refresher) {
        refresher.complete();
      }
    },this.pageParam);
  }

  get canLoadMore():boolean {
    return this.hasMore;
  }

  doInfinite(infiniteScroll) {
    ++this.pageParam.page;
    this.GOODS.getScoreOrderList(v => {
      this.hasMore = !v.last;
      this.orderList = this.orderList.concat(v.content);
      infiniteScroll.complete();
    },this.pageParam);
  }

}
